#include "point_kernel.h"

#include "../math/conversion.h"
#include "../math/int2.h"

#include <array>

namespace ray_tracing
{

	point_kernel_t::point_kernel_t(uint32_t* in_pixels, int in_width, int in_height,
		scene_t* in_scene, calculate_pixel_color_t in_shade)
		: pixels(in_pixels),
		width(in_width),
		height(in_height),
		scene(in_scene),
		shade(in_shade),
		inv_width(1.f / width),
		inv_height(1.f / height),
		ar(width * inv_height)
	{
	}

	void point_kernel_t::operator()(int index) const
	{
		int x = index % width; 
		int y = index / height; 

		float xc = x * inv_width; 
		float yc = y * inv_height; 

		camera_t * rendering_camera = scene->get_rendering_camera();

		if(rendering_camera)
		{
			ray3f ray = rendering_camera->get_ray(xc,yc,ar);

			vec3f output_color = shade(scene, ray, 0);

			pixels[index] = conversion::convert_to_uint32_t(output_color);
		}
	}
}